package com.zrentech.order.data.dbhelper.builder;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.database.Cursor;

import com.zrentech.order.data.busibean.CustomerFeedbackBean;
import com.zrentech.order.data.dbhelper.DatabaseBuilder;

/**
 * 
 * 提供关于菜谱对应的客户评价的创建和解析方面的功能
 * 
 * @author Leon
 */

public class CustomerFeedbackDBuilder extends
		DatabaseBuilder<CustomerFeedbackBean> {

	public static final String TRACK_ID = "id";
	public static final String TRACK_FOODID = "foodID";
	public static final String TRACK_COMMENTS = "comments";
	public static final String TRACK_GRADE = "grade";
	public static final String TRACK_RATING = "rating";

	@Override
	public CustomerFeedbackBean build(Cursor query) {
		int columnId = query.getColumnIndex(TRACK_ID);
		int columnFoodid = query.getColumnIndex(TRACK_FOODID);
		int columnComments = query.getColumnIndex(TRACK_COMMENTS);
		int columnGrade = query.getColumnIndex(TRACK_GRADE);
		int columnRating = query.getColumnIndex(TRACK_RATING);

		CustomerFeedbackBean feedback = new CustomerFeedbackBean();
		feedback.setId(query.getInt(columnId));
		feedback.setFoodID(query.getInt(columnFoodid));
		feedback.setComments(query.getString(columnComments));
		feedback.setGrade(query.getDouble(columnGrade));
		feedback.setRating(query.getDouble(columnRating));
		return feedback;
	}

	public List<CustomerFeedbackBean> buildMore(Cursor query) {
		List<CustomerFeedbackBean> feedbacks = new ArrayList<CustomerFeedbackBean>();
		CustomerFeedbackBean feedback = null;
		if (query.moveToFirst()) {
			for (int i = 0; i < query.getCount(); i++) {
				query.move(i);
				int columnId = query.getColumnIndex(TRACK_ID);
				int columnFoodid = query.getColumnIndex(TRACK_FOODID);
				int columnComments = query.getColumnIndex(TRACK_COMMENTS);
				int columnGrade = query.getColumnIndex(TRACK_GRADE);
				int columnRating = query.getColumnIndex(TRACK_RATING);

				feedback = new CustomerFeedbackBean();
				feedback.setId(query.getInt(columnId));
				feedback.setFoodID(query.getInt(columnFoodid));
				feedback.setComments(query.getString(columnComments));
				feedback.setGrade(query.getDouble(columnGrade));
				feedback.setRating(query.getDouble(columnRating));
				feedbacks.add(feedback);
			}
		}
		return feedbacks;
	}

	@Override
	public ContentValues deconstruct(CustomerFeedbackBean track) {
		ContentValues values = new ContentValues();
		values.put(TRACK_ID, track.getId());
		values.put(TRACK_FOODID, track.getFoodID());
		values.put(TRACK_COMMENTS, track.getComments());
		values.put(TRACK_GRADE, track.getGrade());
		values.put(TRACK_RATING, track.getRating());
		return values;
	}

}
